{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "from sklearn.model_selection import train_test_split, StratifiedKFold\n",
    "from sklearn.metrics import log_loss\n",
    "from sklearn.ensemble import RandomForestClassifier, ExtraTreesClassifier\n",
    "from lightgbm import LGBMClassifier\n",
    "from catboost import CatBoostClassifier\n",
    "from xgboost import XGBClassifier\n",
    "import optuna"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "train = pd.read_csv('train.csv')\n",
    "test = pd.read_csv('test.csv')\n",
    "sample = pd.read_csv('submission.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.concat([train, test], axis= 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.Popularity = df.Popularity.fillna(value=df.Popularity.median(), axis=0)\n",
    "df.key = df.key.fillna(value=df.key.median(), axis=0)\n",
    "df.instrumentalness = df.instrumentalness.fillna(value=df.instrumentalness.median(), axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['popularity_by_artist_max']= df.groupby(['Artist Name'])['Popularity'].transform('max')\n",
    "df['dance_by_artist_mean']= df.groupby(['Artist Name'])['danceability'].transform('mean')\n",
    "df['energy_by_artist_mean']= df.groupby(['Artist Name'])['energy'].transform('mean')\n",
    "df['key_by_artist_mean']= df.groupby(['Artist Name'])['key'].transform('mean')\n",
    "df['loud_by_artist_mean']= df.groupby(['Artist Name'])['loudness'].transform('mean')\n",
    "df['speech_by_artist_mean']= df.groupby(['Artist Name'])['speechiness'].transform('mean')\n",
    "df['acostic_by_artist_mean']= df.groupby(['Artist Name'])['acousticness'].transform('mean')\n",
    "df['instrument_by_artist_mean']= df.groupby(['Artist Name'])['instrumentalness'].transform('mean')\n",
    "df['live_by_artist_mean']= df.groupby(['Artist Name'])['liveness'].transform('mean')\n",
    "df['valence_by_artist_mean']= df.groupby(['Artist Name'])['valence'].transform('mean')\n",
    "df['tempo_by_artist_mean']= df.groupby(['Artist Name'])['tempo'].transform('mean')\n",
    "df['duration_by_artist_mean']= df.groupby(['Artist Name'])['duration_in min/ms'].transform('mean')\n",
    "df['time_by_artist_mean']= df.groupby(['Artist Name'])['time_signature'].transform('mean')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['song_in_min']= df['duration_in min/ms']/60000"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['pops']= df.Popularity + df.danceability + df.energy  + df.loudness + df.speechiness + df.acousticness+ df.instrumentalness + df.liveness + df.valence + df.tempo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['song_by_artist_mean']= df.groupby(['Artist Name'])['song_in_min'].transform('mean')\n",
    "df['pops_by_artist_mean']= df.groupby(['Artist Name'])['pops'].transform('mean')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['popularity_by_singer_and_track_mean']= df.groupby(['Artist Name', 'Track Name'])['Popularity'].transform('mean')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "keys= pd.get_dummies(df.key, drop_first=True, prefix= 'key_')\n",
    "df = df.drop('key', axis= 1)\n",
    "df= pd.concat([df,keys], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "times= pd.get_dummies(df.time_signature, drop_first=True, prefix= 'time_')\n",
    "df = df.drop('time_signature', axis= 1)\n",
    "df= pd.concat([df,times], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['artist_Trck']= df['Artist Name'].astype(str) + '_' + df['Track Name'].astype(str)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Artist Name', 'Track Name', 'artist_Trck']"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[var for var in df.columns if df[var].dtypes == 'O']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['tracks_by_artists']= df.groupby('Artist Name')['Track Name'].transform('count')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "train = df[:17996]\n",
    "test = df[17996:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Artist Name', 'Track Name', 'artist_Trck']"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[var for var in train.columns if train[var].dtypes== 'O']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "cat_cols = ['Artist Name', 'Track Name', 'artist_Trck']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Popularity',\n",
       " 'danceability',\n",
       " 'energy',\n",
       " 'loudness',\n",
       " 'mode',\n",
       " 'speechiness',\n",
       " 'acousticness',\n",
       " 'instrumentalness',\n",
       " 'liveness',\n",
       " 'valence',\n",
       " 'tempo',\n",
       " 'duration_in min/ms',\n",
       " 'Class',\n",
       " 'popularity_by_artist_max',\n",
       " 'dance_by_artist_mean',\n",
       " 'energy_by_artist_mean',\n",
       " 'key_by_artist_mean',\n",
       " 'loud_by_artist_mean',\n",
       " 'speech_by_artist_mean',\n",
       " 'acostic_by_artist_mean',\n",
       " 'instrument_by_artist_mean',\n",
       " 'live_by_artist_mean',\n",
       " 'valence_by_artist_mean',\n",
       " 'tempo_by_artist_mean',\n",
       " 'duration_by_artist_mean',\n",
       " 'time_by_artist_mean',\n",
       " 'song_in_min',\n",
       " 'pops',\n",
       " 'song_by_artist_mean',\n",
       " 'pops_by_artist_mean',\n",
       " 'popularity_by_singer_and_track_mean',\n",
       " 'key__2.0',\n",
       " 'key__3.0',\n",
       " 'key__4.0',\n",
       " 'key__5.0',\n",
       " 'key__6.0',\n",
       " 'key__7.0',\n",
       " 'key__8.0',\n",
       " 'key__9.0',\n",
       " 'key__10.0',\n",
       " 'key__11.0',\n",
       " 'time__1',\n",
       " 'time__3',\n",
       " 'time__4',\n",
       " 'time__5',\n",
       " 'tracks_by_artists']"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[var for var in train.columns if train[var].dtypes!= 'O']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "cont_cols = ['Popularity',\n",
    " 'danceability',\n",
    " 'energy',\n",
    " 'loudness',\n",
    " 'mode',\n",
    " 'speechiness',\n",
    " 'acousticness',\n",
    " 'instrumentalness',\n",
    " 'liveness',\n",
    " 'valence',\n",
    " 'tempo',\n",
    " 'duration_in min/ms',\n",
    " 'popularity_by_artist_max',\n",
    " 'dance_by_artist_mean',\n",
    " 'energy_by_artist_mean',\n",
    " 'key_by_artist_mean',\n",
    " 'loud_by_artist_mean',\n",
    " 'speech_by_artist_mean',\n",
    " 'acostic_by_artist_mean',\n",
    " 'instrument_by_artist_mean',\n",
    " 'live_by_artist_mean',\n",
    " 'valence_by_artist_mean',\n",
    " 'tempo_by_artist_mean',\n",
    " 'duration_by_artist_mean',\n",
    " 'time_by_artist_mean',\n",
    " 'song_in_min',\n",
    " 'pops',\n",
    " 'song_by_artist_mean',\n",
    " 'pops_by_artist_mean',\n",
    " 'popularity_by_singer_and_track_mean',\n",
    " 'key__2.0',\n",
    " 'key__3.0',\n",
    " 'key__4.0',\n",
    " 'key__5.0',\n",
    " 'key__6.0',\n",
    " 'key__7.0',\n",
    " 'key__8.0',\n",
    " 'key__9.0',\n",
    " 'key__10.0',\n",
    " 'key__11.0',\n",
    " 'time__1',\n",
    " 'time__3',\n",
    " 'time__4',\n",
    " 'time__5',\n",
    " 'tracks_by_artists']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "X_train = train[cat_cols+cont_cols]\n",
    "y_train = train.Class\n",
    "X_test = test[cat_cols+cont_cols]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "=============== Fold No: 1 ===============\n",
      "Learning rate set to 0.047371\n",
      "0:\tlearn: 2.2939349\ttest: 2.2937571\tbest: 2.2937571 (0)\ttotal: 377ms\tremaining: 1h 2m 48s\n",
      "500:\tlearn: 0.7481398\ttest: 0.7758466\tbest: 0.7758466 (500)\ttotal: 3m 29s\tremaining: 1h 6m 3s\n",
      "1000:\tlearn: 0.6219397\ttest: 0.7507902\tbest: 0.7507902 (1000)\ttotal: 7m 12s\tremaining: 1h 4m 44s\n",
      "Stopped by overfitting detector  (30 iterations wait)\n",
      "\n",
      "bestTest = 0.7441122221\n",
      "bestIteration = 1334\n",
      "\n",
      "Shrink model to first 1335 iterations.\n",
      "0.7441122220949107\n",
      "=============== Fold No: 2 ===============\n",
      "Learning rate set to 0.047371\n",
      "0:\tlearn: 2.2939603\ttest: 2.2947312\tbest: 2.2947312 (0)\ttotal: 496ms\tremaining: 1h 22m 42s\n",
      "500:\tlearn: 0.7445404\ttest: 0.7692913\tbest: 0.7692231 (499)\ttotal: 3m 31s\tremaining: 1h 6m 51s\n",
      "1000:\tlearn: 0.6163539\ttest: 0.7424348\tbest: 0.7424348 (1000)\ttotal: 7m 6s\tremaining: 1h 3m 56s\n",
      "Stopped by overfitting detector  (30 iterations wait)\n",
      "\n",
      "bestTest = 0.7412702601\n",
      "bestIteration = 1027\n",
      "\n",
      "Shrink model to first 1028 iterations.\n",
      "0.7412702601307348\n",
      "=============== Fold No: 3 ===============\n",
      "Learning rate set to 0.047371\n",
      "0:\tlearn: 2.2944790\ttest: 2.2943607\tbest: 2.2943607 (0)\ttotal: 498ms\tremaining: 1h 23m 1s\n",
      "500:\tlearn: 0.7453070\ttest: 0.7789424\tbest: 0.7789374 (499)\ttotal: 3m 40s\tremaining: 1h 9m 43s\n",
      "1000:\tlearn: 0.6175225\ttest: 0.7570958\tbest: 0.7569618 (997)\ttotal: 7m 9s\tremaining: 1h 4m 22s\n",
      "Stopped by overfitting detector  (30 iterations wait)\n",
      "\n",
      "bestTest = 0.7523619535\n",
      "bestIteration = 1213\n",
      "\n",
      "Shrink model to first 1214 iterations.\n",
      "0.7523619534812477\n",
      "=============== Fold No: 4 ===============\n",
      "Learning rate set to 0.047371\n",
      "0:\tlearn: 2.2939272\ttest: 2.2930996\tbest: 2.2930996 (0)\ttotal: 470ms\tremaining: 1h 18m 18s\n",
      "500:\tlearn: 0.7463293\ttest: 0.7710501\tbest: 0.7710501 (500)\ttotal: 3m 37s\tremaining: 1h 8m 35s\n",
      "1000:\tlearn: 0.6205664\ttest: 0.7465060\tbest: 0.7464342 (983)\ttotal: 7m 12s\tremaining: 1h 4m 49s\n",
      "Stopped by overfitting detector  (30 iterations wait)\n",
      "\n",
      "bestTest = 0.7412987791\n",
      "bestIteration = 1337\n",
      "\n",
      "Shrink model to first 1338 iterations.\n",
      "0.7412987791280218\n",
      "=============== Fold No: 5 ===============\n",
      "Learning rate set to 0.047371\n",
      "0:\tlearn: 2.2935536\ttest: 2.2943257\tbest: 2.2943257 (0)\ttotal: 441ms\tremaining: 1h 13m 27s\n",
      "500:\tlearn: 0.7471139\ttest: 0.8195113\tbest: 0.8195113 (500)\ttotal: 3m 26s\tremaining: 1h 5m 15s\n",
      "1000:\tlearn: 0.6153528\ttest: 0.7958924\tbest: 0.7958924 (1000)\ttotal: 6m 57s\tremaining: 1h 2m 31s\n",
      "Stopped by overfitting detector  (30 iterations wait)\n",
      "\n",
      "bestTest = 0.7938181693\n",
      "bestIteration = 1157\n",
      "\n",
      "Shrink model to first 1158 iterations.\n",
      "0.7938181692879601\n",
      "=============== Fold No: 6 ===============\n",
      "Learning rate set to 0.047371\n",
      "0:\tlearn: 2.2934099\ttest: 2.2952798\tbest: 2.2952798 (0)\ttotal: 447ms\tremaining: 1h 14m 34s\n",
      "500:\tlearn: 0.7460516\ttest: 0.8171847\tbest: 0.8171847 (500)\ttotal: 3m 34s\tremaining: 1h 7m 41s\n",
      "1000:\tlearn: 0.6212809\ttest: 0.7930388\tbest: 0.7929815 (998)\ttotal: 7m 16s\tremaining: 1h 5m 23s\n",
      "Stopped by overfitting detector  (30 iterations wait)\n",
      "\n",
      "bestTest = 0.7893486776\n",
      "bestIteration = 1210\n",
      "\n",
      "Shrink model to first 1211 iterations.\n",
      "0.7893486776269402\n",
      "=============== Fold No: 7 ===============\n",
      "Learning rate set to 0.047371\n",
      "0:\tlearn: 2.2925755\ttest: 2.2981736\tbest: 2.2981736 (0)\ttotal: 443ms\tremaining: 1h 13m 49s\n",
      "500:\tlearn: 0.7443309\ttest: 0.8424837\tbest: 0.8424130 (499)\ttotal: 3m 31s\tremaining: 1h 6m 55s\n",
      "Stopped by overfitting detector  (30 iterations wait)\n",
      "\n",
      "bestTest = 0.8245270103\n",
      "bestIteration = 908\n",
      "\n",
      "Shrink model to first 909 iterations.\n",
      "0.8245270102684863\n",
      "=============== Fold No: 8 ===============\n",
      "Learning rate set to 0.047371\n",
      "0:\tlearn: 2.2987232\ttest: 2.3010771\tbest: 2.3010771 (0)\ttotal: 455ms\tremaining: 1h 15m 47s\n",
      "500:\tlearn: 0.7466875\ttest: 0.7995089\tbest: 0.7994411 (497)\ttotal: 3m 30s\tremaining: 1h 6m 35s\n",
      "1000:\tlearn: 0.6179879\ttest: 0.7753946\tbest: 0.7753946 (1000)\ttotal: 7m 4s\tremaining: 1h 3m 36s\n",
      "Stopped by overfitting detector  (30 iterations wait)\n",
      "\n",
      "bestTest = 0.774120653\n",
      "bestIteration = 1039\n",
      "\n",
      "Shrink model to first 1040 iterations.\n",
      "0.7741206529825393\n",
      "=============== Fold No: 9 ===============\n",
      "Learning rate set to 0.047371\n",
      "0:\tlearn: 2.2993533\ttest: 2.2993102\tbest: 2.2993102 (0)\ttotal: 461ms\tremaining: 1h 16m 53s\n",
      "500:\tlearn: 0.7458227\ttest: 0.8010706\tbest: 0.8010706 (500)\ttotal: 3m 3s\tremaining: 57m 57s\n",
      "1000:\tlearn: 0.6187869\ttest: 0.7796246\tbest: 0.7795531 (983)\ttotal: 6m 33s\tremaining: 58m 58s\n",
      "Stopped by overfitting detector  (30 iterations wait)\n",
      "\n",
      "bestTest = 0.7795530883\n",
      "bestIteration = 983\n",
      "\n",
      "Shrink model to first 984 iterations.\n",
      "0.7795530882532616\n",
      "=============== Fold No: 10 ===============\n",
      "Learning rate set to 0.047371\n",
      "0:\tlearn: 2.2959571\ttest: 2.2976397\tbest: 2.2976397 (0)\ttotal: 477ms\tremaining: 1h 19m 31s\n",
      "500:\tlearn: 0.7457890\ttest: 0.7865753\tbest: 0.7865753 (500)\ttotal: 3m 32s\tremaining: 1h 7m 8s\n",
      "1000:\tlearn: 0.6164739\ttest: 0.7652535\tbest: 0.7649527 (990)\ttotal: 7m\tremaining: 1h 3m 2s\n",
      "Stopped by overfitting detector  (30 iterations wait)\n",
      "\n",
      "bestTest = 0.7649526987\n",
      "bestIteration = 990\n",
      "\n",
      "Shrink model to first 991 iterations.\n",
      "0.7649526986904605\n",
      "0.7705363511944563\n"
     ]
    }
   ],
   "source": [
    "n_folds = 10\n",
    "subbed = []\n",
    "kf = StratifiedKFold(n_splits=n_folds, shuffle=True, random_state=10)\n",
    "\n",
    "\n",
    "for fold, (train_idx, test_idx) in enumerate(kf.split(X_train, y_train)):\n",
    "    print('=============== Fold No:',fold+1,'===============')\n",
    "    X_tr, X_tst = X_train.iloc[train_idx], X_train.iloc[test_idx]\n",
    "    y_tr, y_tst = y_train.iloc[train_idx], y_train.iloc[test_idx]\n",
    "    \n",
    "    model = CatBoostClassifier(n_estimators=10000, random_state=10, eval_metric= 'MultiClass', cat_features=cat_cols)\n",
    "    model.fit(X_tr, y_tr,eval_set=[(X_tst, y_tst)], early_stopping_rounds=30, verbose=500)\n",
    "    print(log_loss(y_tst, model.predict_proba(X_tst)))\n",
    "    subbed.append(log_loss(y_tst, model.predict_proba(X_tst)))\n",
    "    pred = model.predict_proba(X_test)\n",
    "print(np.mean(subbed))\n",
    "#0.7796464371342455\n",
    "#0.776109144116776\n",
    "#"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>9</th>\n",
       "      <th>10</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.000482</td>\n",
       "      <td>0.541627</td>\n",
       "      <td>0.012778</td>\n",
       "      <td>0.000032</td>\n",
       "      <td>0.000060</td>\n",
       "      <td>0.000782</td>\n",
       "      <td>0.116931</td>\n",
       "      <td>0.000047</td>\n",
       "      <td>0.002941</td>\n",
       "      <td>0.016747</td>\n",
       "      <td>0.307574</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.000031</td>\n",
       "      <td>0.005524</td>\n",
       "      <td>0.000881</td>\n",
       "      <td>0.000003</td>\n",
       "      <td>0.000007</td>\n",
       "      <td>0.001310</td>\n",
       "      <td>0.018118</td>\n",
       "      <td>0.000003</td>\n",
       "      <td>0.806412</td>\n",
       "      <td>0.002381</td>\n",
       "      <td>0.165329</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.000020</td>\n",
       "      <td>0.004224</td>\n",
       "      <td>0.000139</td>\n",
       "      <td>0.000005</td>\n",
       "      <td>0.000126</td>\n",
       "      <td>0.015953</td>\n",
       "      <td>0.006832</td>\n",
       "      <td>0.000003</td>\n",
       "      <td>0.001910</td>\n",
       "      <td>0.924317</td>\n",
       "      <td>0.046471</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.000211</td>\n",
       "      <td>0.008172</td>\n",
       "      <td>0.000328</td>\n",
       "      <td>0.000034</td>\n",
       "      <td>0.000336</td>\n",
       "      <td>0.022143</td>\n",
       "      <td>0.014413</td>\n",
       "      <td>0.000012</td>\n",
       "      <td>0.002147</td>\n",
       "      <td>0.868666</td>\n",
       "      <td>0.083538</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.002031</td>\n",
       "      <td>0.000234</td>\n",
       "      <td>0.000092</td>\n",
       "      <td>0.000123</td>\n",
       "      <td>0.010005</td>\n",
       "      <td>0.000638</td>\n",
       "      <td>0.000330</td>\n",
       "      <td>0.000025</td>\n",
       "      <td>0.000242</td>\n",
       "      <td>0.981666</td>\n",
       "      <td>0.004614</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7708</th>\n",
       "      <td>0.000011</td>\n",
       "      <td>0.001146</td>\n",
       "      <td>0.002392</td>\n",
       "      <td>0.000005</td>\n",
       "      <td>0.000012</td>\n",
       "      <td>0.004213</td>\n",
       "      <td>0.003305</td>\n",
       "      <td>0.000002</td>\n",
       "      <td>0.000203</td>\n",
       "      <td>0.978861</td>\n",
       "      <td>0.009850</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7709</th>\n",
       "      <td>0.000017</td>\n",
       "      <td>0.079585</td>\n",
       "      <td>0.034459</td>\n",
       "      <td>0.000005</td>\n",
       "      <td>0.000004</td>\n",
       "      <td>0.002520</td>\n",
       "      <td>0.133962</td>\n",
       "      <td>0.000028</td>\n",
       "      <td>0.365121</td>\n",
       "      <td>0.008791</td>\n",
       "      <td>0.375509</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7710</th>\n",
       "      <td>0.116189</td>\n",
       "      <td>0.015160</td>\n",
       "      <td>0.003944</td>\n",
       "      <td>0.242357</td>\n",
       "      <td>0.015247</td>\n",
       "      <td>0.039679</td>\n",
       "      <td>0.029819</td>\n",
       "      <td>0.003744</td>\n",
       "      <td>0.000973</td>\n",
       "      <td>0.465906</td>\n",
       "      <td>0.066982</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7711</th>\n",
       "      <td>0.000114</td>\n",
       "      <td>0.122930</td>\n",
       "      <td>0.041208</td>\n",
       "      <td>0.000017</td>\n",
       "      <td>0.000046</td>\n",
       "      <td>0.004730</td>\n",
       "      <td>0.341832</td>\n",
       "      <td>0.000016</td>\n",
       "      <td>0.000595</td>\n",
       "      <td>0.015946</td>\n",
       "      <td>0.472567</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7712</th>\n",
       "      <td>0.000135</td>\n",
       "      <td>0.016055</td>\n",
       "      <td>0.004943</td>\n",
       "      <td>0.000052</td>\n",
       "      <td>0.000131</td>\n",
       "      <td>0.819493</td>\n",
       "      <td>0.044542</td>\n",
       "      <td>0.000015</td>\n",
       "      <td>0.000858</td>\n",
       "      <td>0.095765</td>\n",
       "      <td>0.018010</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>7713 rows × 11 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            0         1         2         3         4         5         6   \\\n",
       "0     0.000482  0.541627  0.012778  0.000032  0.000060  0.000782  0.116931   \n",
       "1     0.000031  0.005524  0.000881  0.000003  0.000007  0.001310  0.018118   \n",
       "2     0.000020  0.004224  0.000139  0.000005  0.000126  0.015953  0.006832   \n",
       "3     0.000211  0.008172  0.000328  0.000034  0.000336  0.022143  0.014413   \n",
       "4     0.002031  0.000234  0.000092  0.000123  0.010005  0.000638  0.000330   \n",
       "...        ...       ...       ...       ...       ...       ...       ...   \n",
       "7708  0.000011  0.001146  0.002392  0.000005  0.000012  0.004213  0.003305   \n",
       "7709  0.000017  0.079585  0.034459  0.000005  0.000004  0.002520  0.133962   \n",
       "7710  0.116189  0.015160  0.003944  0.242357  0.015247  0.039679  0.029819   \n",
       "7711  0.000114  0.122930  0.041208  0.000017  0.000046  0.004730  0.341832   \n",
       "7712  0.000135  0.016055  0.004943  0.000052  0.000131  0.819493  0.044542   \n",
       "\n",
       "            7         8         9         10  \n",
       "0     0.000047  0.002941  0.016747  0.307574  \n",
       "1     0.000003  0.806412  0.002381  0.165329  \n",
       "2     0.000003  0.001910  0.924317  0.046471  \n",
       "3     0.000012  0.002147  0.868666  0.083538  \n",
       "4     0.000025  0.000242  0.981666  0.004614  \n",
       "...        ...       ...       ...       ...  \n",
       "7708  0.000002  0.000203  0.978861  0.009850  \n",
       "7709  0.000028  0.365121  0.008791  0.375509  \n",
       "7710  0.003744  0.000973  0.465906  0.066982  \n",
       "7711  0.000016  0.000595  0.015946  0.472567  \n",
       "7712  0.000015  0.000858  0.095765  0.018010  \n",
       "\n",
       "[7713 rows x 11 columns]"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "out = pd.DataFrame(pred)\n",
    "out"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "out = out.rename(columns={0:'Acoustic/Folk_0',\n",
    "               1:'Alt_Music_1',\n",
    "               2:'Blues_2',\n",
    "               3:'Bollywood_3',\n",
    "               4:'Country_4',\n",
    "               5:'HipHop_5',\n",
    "               6:'Indie Alt_6',\n",
    "               7:'Instrumental_7',\n",
    "               8:'Metal_8',\n",
    "               9:'Pop_9',\n",
    "               10:'Rock_10'})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "out.to_csv('out6.csv', index= False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
